﻿''' <summary>
''' Allows to change the Key-Input of the Game.
''' </summary>
''' <remarks></remarks>
Public Class ObjektKeymenue
    Inherits ObjektFormMenue
    Dim ArraNames As New List(Of String)
    Dim ArraLabel As New List(Of Integer)
    Public Sub New()
        MyBase.New()
        If DataSettings.Verhaeltnis = Hauptmenue.Breitbild Then
            Objektverwalter.LoadHintergrund(DataSettings.Resourcenpfad + "Backgrounds\OptionenGross.png")
        Else
            Objektverwalter.LoadHintergrund(DataSettings.Resourcenpfad + "Backgrounds\Optionen.png")
        End If
        Dim P As New ObjektPanel2D(New Rectangle(0, 0, DataSettings.BildschirmBreite, DataSettings.BildschirmHoehe), New PointF, 1, False)
        Dim R As Integer
        Dim ItemsPerRow As Integer = Math.DivRem(P.Rechteck.Width - 20, 200, R)
        Dim Names As String() = [Enum].GetNames(Konsole.Settings._2D3D.GetType)
        Dim CY As Integer = 20
        Dim CX As Integer = 20 + R / 2
        For Each Name In Names
            Dim IniValue As Object = GetIniValue([Enum].Parse(Konsole.Settings._2D3D.GetType, Name))
            If TypeOf IniValue Is Keys Then
                Array.Resize(Labels, Labels.Length + 1)
                ArraNames.Add(Name)
                ArraLabel.Add(Labels.Length - 1)
                Labels(Labels.Length - 1) = New ObjektLabel(CX, CY + 30, DataSettings.Resourcenpfad + "Objects\Transparent.png", New String() {CType(IniValue, Keys).ToString}, New Point, 16, 0, New PointF(), P)
                NeuButton(CX, CY, DataSettings.Resourcenpfad + "Objects\Button.png", Name, New PointF(), , , , P)
                CX += 200
                If CX >= P.Rechteck.Width - R / 2 Then
                    CX = 20 + R / 2
                    CY += 90
                End If
            End If
        Next
        If CY < DataSettings.BildschirmHoehe - 30 Then
            NeuButton(DataSettings.BildschirmBreite / 2 - 55, DataSettings.BildschirmHoehe - 30, DataSettings.Resourcenpfad + "Objects\Button.png", "Zurueck", New PointF(), , , , P)
        Else
            NeuButton(DataSettings.BildschirmBreite / 2 - 55, CY + 30, DataSettings.Resourcenpfad + "Objects\Button.png", "Zurueck", New PointF(), , , , P)
        End If
        If CY < DataSettings.BildschirmHoehe - 60 Then
            NeuButton(DataSettings.BildschirmBreite / 2 - 55, DataSettings.BildschirmHoehe - 60, DataSettings.Resourcenpfad + "Objects\Button.png", "Speichern", New PointF(), , , , P)
        Else
            NeuButton(DataSettings.BildschirmBreite / 2 - 55, CY + 60, DataSettings.Resourcenpfad + "Objects\Button.png", "Speichern", New PointF(), , , , P)
        End If
        NeuPanel(P)
    End Sub

    Public Overrides Sub ChangeWindowSize(ByVal PosChange As System.Drawing.Point)

    End Sub

    Public Overrides Sub Frame()

    End Sub

    Public Overrides Sub IniMenue()

    End Sub

    Public Overrides Sub KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs)
        Select Case e.KeyCode
            Case Keys.Delete
                Hauptmenue.Ini(Hauptmenue.Formmodi.Optionen)
        End Select
    End Sub

    Public Overrides Sub KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs)
        Select Case e.KeyCode
            Case Keys.Escape
                Hauptmenue.Ini(Hauptmenue.Formmodi.Optionen)
        End Select
    End Sub

    Public Overrides Sub Malen()
        MyBase.ObjekteMalen()
    End Sub

    Public Overrides Sub MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
        Me.checkMouseDownObjekte(e.X, e.Y)
    End Sub

    Public Overrides Sub MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
        Me.MouseMoveObjekte(e.X, e.Y)
    End Sub

    Public Overrides Sub MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
        Dim F As String = checkMouseUPObjekte(e.X, e.Y)
        If F <> "" Then
            Select Case F.ToLower
                Case "zurueck"
                    Hauptmenue.Ini(Hauptmenue.Formmodi.Optionen)
                Case "speichern"
                    Dim Doppelt As Boolean = False
                    Dim Names As String() = [Enum].GetNames(Konsole.Settings._2D3D.GetType)
                    'Check if ever Key is only used a single time.
                    For Each Name In Names
                        Dim IniValue As Object = GetIniValue([Enum].Parse(Konsole.Settings._2D3D.GetType, Name))
                        If TypeOf IniValue Is Keys Then
                            For Each CompareName In Names
                                If Name <> CompareName Then
                                    Dim IniValue2 As Object = GetIniValue([Enum].Parse(Konsole.Settings._2D3D.GetType, CompareName))
                                    If TypeOf IniValue2 Is Keys Then
                                        If IniValue = IniValue2 Then
                                            Doppelt = True
                                            Exit For
                                        End If
                                    End If
                                End If
                            Next
                        End If
                        If Doppelt Then
                            Exit For
                        End If
                    Next
                    If Not Doppelt Then
                        DataSettings.MySettingsIniSave()
                    Else 'Inform Player about unable to save Keys
                        MessageBox.ShowMessageBox("Eine oder mehrere Tasten sind doppelt belegt!", MsgBoxStyle.OkOnly, "Speichern ummöglich")
                    End If
                Case Else
                    If MessageBox.ShowKeyInput() = MsgBoxResult.Ok Then
                        SaveIniValue(F, MessageBox.CurrentKey)
                        For I = 0 To ArraNames.Count - 1
                            If ArraNames(I) = F Then
                                Labels(ArraLabel(I)).Text.neuerText(New String() {MessageBox.CurrentKey.ToString}, Nothing)
                                Exit Sub
                            End If
                        Next
                    End If
            End Select
        End If
    End Sub

    Public Overrides Sub MouseWheel(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)

    End Sub

    Public Overrides Sub SetMausBild()

    End Sub

    Public Overrides Sub SprachEingabe(ByVal Eingabe As String)

    End Sub
End Class
